import { getLogByPage } from '@/services/login/logging';
import type { ActionType } from '@ant-design/pro-table';
import ProTable from '@ant-design/pro-table';
import React from 'react';
import { useModel } from 'umi';

import { useRef } from 'react';
const Operator: React.FC<{}> = () => {
  const { initialState, setInitialState } = useModel('@@initialState');
  debugger;
  const { currentUser } = initialState;

  const columns: ProColumns[] = [
    {
      title: '序号',
      dataIndex: 'index',
      valueType: 'index',
      width: 50,
    },
    {
      title: '用户名称', //表头显示的名称
      search: false,
      dataIndex: 'username', // 列数据在数据项中对应的路径，支持通过数组查询嵌套路径
      width: 90,
    },

    {
      title: '描述', //表头显示的名称
      search: false,
      dataIndex: 'description',
      width: 90,
    },

    {
      title: '创建日期', //表头显示的名称
      search: false,
      dataIndex: 'createDate',
      width: 160,
    },

    {
      title: '请求耗时', //表头显示的名称
      search: false,
      dataIndex: 'time',
      width: 90,
    },
    {
      title: '入参', //表头显示的名称
      search: false,
      dataIndex: 'params',
      ellipsis: true,
    },
  ];

  const actionRef = useRef<ActionType>();
  return (
    <ProTable //表格Pro组件
      headerTitle="个人操作记录" //表头
      actionRef={actionRef} //用于触发刷新操作等，看api
      rowKey="id" //表格行 key 的取值，可以是字符串或一个函数
      request={async (params = {}, sort, filter) => {
        console.log(params, sort, filter);
        const result = await getLogByPage({ ...params, username: currentUser.name });
        // console.log(result);
        return {
          data: result.data.content,
          total: result.data.totalElements,
          success: result.success,
        };
        // return  await new Promise({data:[{loginName:}], total:10, success: 0})
        // return {data:[], total:10, success: 0}
      }} //请求数据的地方，例子是用mock模拟数据，我是在后台请求的数据
      columns={columns} //上面定义的
      rowSelection={{}}
    />
  );
};
export default Operator;
